﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebGioiThieu.Models;

namespace WebGioiThieu.Controllers
{
    public class CommentController : Controller
    {
        private IntroductionWebDBEntities db = new IntroductionWebDBEntities();
        //
        // GET: /Comment/
        [HttpPost]
        public ActionResult CreateComment(FormCollection c, bool ajaxVar = false)
        {
            Comment comment = new Comment
            {
                HoTen = c["HoTen"],
                Email = c["Email"],
                NoiDung= c["NoiDung"],
                TourID = int.Parse(c["tourId"]),
                Publish = false,
                Time= DateTime.Now,
            };
            db.Comments.Add(comment);
            db.SaveChanges();

            if (ajaxVar)
            {
                ViewBag.rs = "{rs:1}";
                return View();
            }
            else
            {
                return RedirectToAction("details", "Tour", new { id = c["id"] });
            }
        }
    }
}
